programming4us
           
 
 
Windows

SOA with .NET and Windows Azure : Service Implementation with WCF (part 2)

- Free product key for windows 10
- Free Product Key for Microsoft office 365
- Malwarebytes Premium 3.7.1 Serial Keys (LifeTime) 2019
12/15/2010 11:25:41 AM

A Sample Implementation

Various concepts were previously covered, including Data Contracts, Message Contracts, Endpoint Address, Faults, Behaviors, Bindings, Metadata Exchange (MEX) and others.

The following example pulls together several of the individual elements, attributes and classes to present a very simple but complete service implementation. The Greeting service has two operations: Greet1 and Greet2. Greet1 accepts a name parameter and returns a string with “Hello” prefixed to the name. Greet2 accepts a data contract comprised of populated First Name and Last Name fields and returns a string with “Hello” appended to the name.

Example 3.
using System;
using System.ServiceModel;
using System.Runtime.Serialization;
namespace HelloService
{
[ServiceContract(Namespace = "HelloService", Name = "IGreet")]
public interface IGreet
{
[OperationContract]
string Greet1(string name);
[OperationContract]
string Greet2(NameContract nameContractValue);
}
public class Greet : IGreet
{
public string Greet1(string name)
{
return "Hello: " + name;
}
public string Greet2(NameContract nameContractValue)
{
return "Hello: " + nameContractValue.FirstName;
}
}
[DataContract]
public class NameContract
{
[DataMember]
public string FirstName {get; set;}
[DataMember]
public string LastName {get; set;}
}
}


In order to host the service in IIS, we need to create an “.svc” file and reference the service using the ServiceHost directive as shown here:

Example 4.
<%
@ServiceHost Language=C# Debug="true"
Service="HelloService.Greet"
CodeBehind="~/App_Code/Greet.cs"
%>

Finally, we need to configure the service endpoint’s address, binding, and contract in the Web.Config file:

Example 5.
<configuration
xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
<system.serviceModel>
<services>
<service name="HelloService.Greet"
behaviorConfiguration="GreetTypeBehaviors">
<endpoint
address="mex"
binding="mexHttpBinding"
contract="HelloService.IGreet" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="GreetTypeBehaviors" >
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>


The httpGetEnabled=true behavior indicates a WSDL definition is published with the service. includeExceptionDetailInFaults=true configures the service to return unhandled exceptions as faults and includeExceptionDetailInFaults=false will raise the actual exception to the service consumer.

Other -----------------
- Windows 7 : Thwarting Spam with Windows Live Mail’s Junk Filter (part 2) - Blocking Countries and Languages
- Windows 7 : Thwarting Spam with Windows Live Mail’s Junk Filter (part 1)
- Windows 7 : Configuring Windows Defender to Scan Email
- Windows 7 : Protecting Yourself Against Email Viruses
- Windows 7 : Understand Internet Explorer’s Advanced Security Options
- SOA with .NET and Windows Azure : WCF Services - Overview
- SOA with .NET and Windows Azure : Web Services (ASMX and WSE)
- Windows 7 : Enhancing Your Browsing Security (part 6) - Managing Add-Ons
- Windows 7 : Enhancing Your Browsing Security (part 5) - Encoding Addresses to Prevent IDN Spoofing
- Windows 7 : Enhancing Your Browsing Security (part 4) - Thwarting Phishers with the SmartScreen Filter
- Windows 7 : Enhancing Your Browsing Security (part 3) - Changing a Zone’s Security Level
- Windows 7 : Enhancing Your Browsing Security (part 2) - Adding and Removing Zone Sites
- Windows 7 : Enhancing Your Browsing Security (part 1) - Blocking Pop-Up Windows
- Windows 7 : Configuring Internet Explorer Security - Enhancing Your Browsing Privacy (part 4) - InPrivate Browsing and Filtering
- Windows 7 : Configuring Internet Explorer Security - Enhancing Your Browsing Privacy (part 3) - Enhancing Online Privacy by Managing Cookies
- Windows 7 : Configuring Internet Explorer Security - Enhancing Your Browsing Privacy (part 2) - Clearing the Address Bar List
- Windows 7 : Configuring Internet Explorer Security - Enhancing Your Browsing Privacy (part 1)
- Windows 7 : Managing Windows Firewall (part 2)
- Windows 7 : Managing Windows Firewall (part 1)
- Windows 7 : Checking Your Computer’s Security Settings (part 2)
 
 
 
Top 10
 
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 2) - Wireframes,Legends
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 1) - Swimlanes
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Formatting and sizing lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Adding shapes to lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Sizing containers
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 3) - The Other Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 2) - The Data Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 1) - The Format Properties of a Control
- Microsoft Access 2010 : Form Properties and Why Should You Use Them - Working with the Properties Window
- Microsoft Visio 2013 : Using the Organization Chart Wizard with new data
- First look: Apple Watch

- 3 Tips for Maintaining Your Cell Phone Battery (part 1)

- 3 Tips for Maintaining Your Cell Phone Battery (part 2)
programming4us programming4us